package Blog

import (
	"FromNowOnPromote/博客系统/Tblog/controllers"
	"FromNowOnPromote/博客系统/Tblog/models"
	"FromNowOnPromote/博客系统/Tblog/models/Blog"
)

//提供接口去阅读博客
type ViewBlog struct {
	controllers.MainController
}

func (this *ViewBlog) Get() {
	blogID := this.Ctx.Input.Param(":blogid")
	db := models.ConnDb()
	defer db.Close()
	var tb Blog.TBloginfo
	err1 := db.Where("blog_id = ?", blogID).Find(&tb).Error
	if err1 != nil {
		body := map[string]interface{}{"code": 300, "msg": "异常请求"}
		this.Data["json"] = body
		this.ServeJSON()
		return
	}
	body := map[string]interface{}{"code": 200, "data": map[string]interface{}{
		"blogid":    tb.BlogId,
		"title":     tb.BlogTitle,
		"url":       tb.BlogUrl,
		"context":   tb.BlogContent,
		"category":  tb.Category,
		"edit_type": tb.EditType,
	}}
	this.Data["json"] = body
	this.ServeJSON()
}
